﻿package  {
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.Sprite;

	public class BarChart extends LineChart {
		
		public function BarChart()
		{
			super();
			addEventListener(MouseEvent.MOUSE_MOVE, MouseHover);
		}
		
		private function MouseHover(e:MouseEvent)
		{
			trace(e.stageX);
		}

		public override function Init(sw:Number, sh:Number)
		{
			stageWidth = sw;
			stageHeight = sh;
			
			if(dataPoints.length <= 0)
			{
				return void;
			}
			
			graphics.clear();
			for(var i:int = 0; i < dataPoints.length; i++)
			{
				var spread:Number = stageWidth / dataPoints[i].length;
				var barWidth:Number = stageWidth / dataPoints[i].length / 2;
				var currentSpread:Number = barWidth / 2;
			
				graphics.lineStyle(2, colorArray[i]);
				graphics.beginFill(colorArray[i], 0.7);
		
				var yScale:Number = ScaleY(-1);
				graphics.moveTo(currentSpread, yScale);

				for(var j:int = 0; j < dataPoints[i].length; j++)
				{
					yScale = ScaleY(-1);
					graphics.lineTo(currentSpread, yScale);
					yScale = ScaleY(dataPoints[i][j]);
					graphics.lineTo(currentSpread, yScale);
					graphics.lineTo(currentSpread + barWidth, yScale);
					yScale = ScaleY(-1);
					graphics.lineTo(currentSpread + barWidth, yScale);
					currentSpread += spread;
				}
				
				graphics.lineStyle(1, 0x666666);
				graphics.lineTo(barWidth, stageHeight + 1);
				graphics.endFill();
			}
		}
	}
	
}